//
//  ZZCMenuView.m
//  ZZC-Finance
//
//  Created by mac on 2017/5/26.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "ZZCMenuView.h"

@interface ZZCMenuView ()<UITableViewDelegate,UITableViewDataSource,UIGestureRecognizerDelegate,UIScrollViewDelegate>
@property (nonatomic, strong) UITableView *firstTabView;
@property (nonatomic, assign) NSInteger firstIndex;
@property (nonatomic, strong) NSArray *firstArray;
@property (nonatomic, assign) CGRect viewFrame;
@end
@implementation ZZCMenuView

- (instancetype)initWithFrame:(CGRect)frame contentArray:(NSArray *)contentArr {
    
    if (self = [super initWithFrame:frame]) {
        self.viewFrame = frame;
        self.firstArray = contentArr;
        self.firstIndex = -1;
        self.userInteractionEnabled = YES;
        [self addSubview:self.firstTabView];
        [self.firstTabView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellId"];
    }
    return self;
}

- (UITableView *)firstTabView{
    
    if (!_firstTabView) {
        _firstTabView = [[UITableView alloc] initWithFrame:CGRectMake(100, 0,ZZCScreenW/3, 132) style:UITableViewStylePlain];
        _firstTabView.delegate = self;
        _firstTabView.dataSource = self;
        _firstTabView.showsVerticalScrollIndicator = NO;
        _firstTabView.layer.borderColor = [UIColor blackColor].CGColor;
        _firstTabView.layer.borderWidth = .5;
        _firstTabView.tag = 1000;
        if ([_firstTabView respondsToSelector:@selector(setSeparatorInset:)]){
            [_firstTabView setSeparatorInset:UIEdgeInsetsMake(0, -10, 0, 0)];
        }
        
        if ([_firstTabView respondsToSelector:@selector(setLayoutMargins:)]){
            [_firstTabView setLayoutMargins:UIEdgeInsetsMake(0, -10, 0, 0)];
        }
    }
    return _firstTabView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.firstArray.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellId" forIndexPath:indexPath];
    
    cell.textLabel.text = [NSString stringWithFormat:@"%@",self.firstArray[indexPath.row]];
    
    
    if (self.firstIndex == indexPath.row) {
        [cell.textLabel setTextColor:[UIColor orangeColor]];
    }else{
        [cell.textLabel setTextColor:[UIColor blackColor]];
    }
    return cell;
    
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (tableView.tag == 1000) {
        _firstIndex = indexPath.row;
        _block(NO,self.firstArray[indexPath.row]);
    }
}

@end
